<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vue.js</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="stylesheet" href="style.css" />
    <script src="vue.js"></script>
  </head>
  <body onload="createContains('canvas',8),draw()">
    <div id="vue-app"></div>
    <!-- 别惹我惹我我就扔vue里vue-for生成了 -->
    <div id="canvas-box"></div>
    <script src="app.js"></script>
    <script>
      const createCanvas = function (ids, operations) {
          /** @type {HTMLCanvasElement} */
        if (ids.length !== operations.length) return '给爷滚,数据都给错了'
        for (let i = 0; i < ids.length; i++) {
          const canvas = document.getElementById(ids[i])
          let ctx = ''
          if (canvas.getContext) {
            ctx = canvas.getContext('2d')
          }
          ctx.beginPath()
          ctx.fillStyle = 'red'
          ctx.fillRect(50, 50, 100, 100)
          ctx.globalCompositeOperation = operations[i]
          ctx.fillStyle = 'green'
          ctx.arc(150, 150, 50, 0, Math.PI * 2)
          ctx.fill()
        }
      }

      function draw() {
        const arr = []
        let str = ''
        for (let i = 1; i <= 8; i++) {
          str = `canvas${i}`
          arr.push(str)
        }
        // console.log(arr)
        createCanvas(arr, [
          'source-over',
          'destination-over',
          'source-atop',
          'destination-atop',
          'source-in',
          'destination-in',
          'source-out',
          'destination-out',
        ])
      }

      function createContains(element, number) {
        console.log('执行这里')
        let html = ''
        for (let i = 1; i <= number; i++) {
          html += `<${element} id="canvas${i}" width="300" height="300"></${element}>`
        }
        document.getElementById('canvas-box').innerHTML = html
      }
    </script>
  </body>
</html>
